package Class

import (
	"OnlineRetailers/controllers/errorDeal"
	"OnlineRetailers/models/Admin"
	"OnlineRetailers/models/Admin/resMes"
	error2 "OnlineRetailers/models/errorDeal"
	"fmt"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
)

type GetSmallClass struct {
	beego.Controller
}

func (c *GetSmallClass) GetSmallClass() {
	defer func() {
		c.Ctx.Output.Header("Access-Control-Allow-Origin", "*")
		c.Ctx.Output.Status = 200
		c.ServeJSON()
	}()
	var addr = "/USERSmallClass/GetSmallClass"
	res := resMes.GetSmallClass{}
	smallClasses := []*Admin.SmallClass{}
	log := &error2.Log{}
	var err error
	o := orm.NewOrm()

	begin, err := c.GetInt("begin", 0)
	if err != nil {
		c.Data["json"] = errorDeal.ErrMess(log, "400", err, addr, err.Error())
		return
	}

	fmt.Println(begin)
	sql := "select * from `small_class` order by `small_class_id` desc"
	_, err = o.Raw(sql).QueryRows(&smallClasses)

	if err != nil {
		c.Data["json"] = errorDeal.ErrMess(log, "400", err, addr, err.Error())
		return
	}

	err = GetClass(smallClasses)
	if err != nil {
		c.Data["json"] = errorDeal.ErrMess(log, "400", err, addr, err.Error())
		return
	}
	res.SmallClass = smallClasses
	res.Code = "200"
	c.Data["json"] = res

}
